export default class Rectangle {
  /**
   * @param {number} left
   * @param {number} top
   * @param {number} width 宽度
   * @param {number} height 高度
   * @param {number} xSpeed 横向速度
   * @param {number} ySpeed 纵向速度
   * @param dom 元素
   */
  constructor(left, top, width, height, xSpeed, ySpeed, dom) {
    this.left = left;
    this.top = top;
    this.width = width;
    this.height = height;
    this.xSpeed = xSpeed;
    this.ySpeed = ySpeed;
    this.dom = dom;
  }

  /**
   * 绘制矩形
   */
  render() {
    this.dom.style.left = this.left + 'px';
    this.dom.style.top = this.top + 'px';
    this.dom.style.width = this.width + 'px';
    this.dom.style.height = this.height + 'px';
  }

  /**
   * 移动矩形
   */
  move(duration) {
    this.left += this.xSpeed * duration;
    this.top += this.ySpeed * duration;

    if (this.onMove) {
      this.onMove()
    }
    this.render();
  }
}
